﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HelperPrototype.TabPageControls
{
    public partial class SuaTrangThaiQuyTrinh : UserControl
    {
        public SuaTrangThaiQuyTrinh()
        {
            InitializeComponent();
        }

        private void SuaTrangThaiQuyTrinh_Load(object sender, EventArgs e)
        {
            loadData();
        }

        private void loadData()
        {
            _DB.DataClasses1DataContext dc = new _DB.DataClasses1DataContext();
            dgvTrangThai.Rows.Clear();
            foreach (_DB.TrangThaiQuyTrinhMuaHang t in dc.TrangThaiQuyTrinhMuaHangs)
            {
                DataGridViewRow r = new DataGridViewRow();
                r.CreateCells(dgvTrangThai);
                r.Cells[0].Value = t.ID;
                r.Cells[1].Value = t.MoTa;

                dgvTrangThai.Rows.Add(r);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _DB.DataClasses1DataContext dc = new _DB.DataClasses1DataContext();
            foreach (_DB.TrangThaiQuyTrinhMuaHang t in dc.TrangThaiQuyTrinhMuaHangs)
            foreach (DataGridViewRow r in dgvTrangThai.Rows)
            {
                if (t.ID == (int) r.Cells[0].Value)
                {
                    t.MoTa = (string) r.Cells[1].Value;
                }
            }
            dc.SubmitChanges();
            MessageBox.Show("OK");
        }
    }
}
